package com.hhw.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.hhw.entity.User;
import com.hhw.util.DBUtil;


public class DelUserDao {
			
	
	
	/*
	 * 验证该用户是否存在<根据id>
	 */
	public boolean isExist(int user_id){
		return findUsertById(user_id)==null?false:true;
	}
	
	
	/*
	 * 删除用户方法<根据id>
	 */
	public boolean deleteUserByid(int user_id){
		try{
			Connection con=DBUtil.getConnection();
			PreparedStatement pstm=con.prepareStatement("delete from user where user_id=?");
			pstm.setInt(1, user_id);
			int rs=pstm.executeUpdate();
			if(rs>0){
				return true;
			}else{
				return false;
			}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	
	/*
	 * 根据id查询用户
	 */
	public User findUsertById(int id){
		try{
			Connection con=DBUtil.getConnection();
			PreparedStatement pstm=con.prepareStatement("select * from user where user_id=?");
			pstm.setInt(1, id);
			ResultSet rs=pstm.executeQuery();
			User p=null;
			while(rs.next()){
				p=new User();
			p.setUser_id(rs.getInt(1));
			p.setUser_name(rs.getString(2));
			p.setUser_name(rs.getString(3));
			p.setUser_sex(rs.getString(4));
			p.setUser_phone(rs.getString(5));
			p.setUser_add(rs.getString(6));
				
			}
			return p;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	
	
}
